//
//  HistoryListTableViewCell.swift
//  CheckmeRing
//
//  Created by 董鹏 on 2022/2/19.
//

import UIKit

class HistoryListTableViewCell: UITableViewCell {

    @IBOutlet weak var bgLineView: UIView!
    /// 9月16日（木）
    @IBOutlet weak var monthLabel: UILabel!
    /// 14:06-14:07
    @IBOutlet weak var minuteLabel: UILabel!
    @IBOutlet weak var minSpO2Label: UILabel!
    
    var modelList: [RModel]? {
        didSet {
            
            guard let modelList = modelList else { return }
            if modelList.count == 0 {
                return
            }
            self.monthLabel.text = formatTimeStamp(time: modelList.last!.timeStamp, format: "MM/dd")
            self.minuteLabel.text = formatTimeStamp(time: modelList.first!.timeStamp, format: "HH:mm") + "-" + formatTimeStamp(time: modelList.last!.timeStamp, format: "HH:mm")
            
            // 最低spo2
            var minSpO2 = 1000
            for obj in modelList {
                minSpO2 = min(minSpO2, obj.spo2)
            }
            self.minSpO2Label.text = String(minSpO2) + "%"
            
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        self.bgLineView.layer.cornerRadius = 6
        self.bgLineView.layer.borderWidth = 1
        self.bgLineView.layer.borderColor = hexColor("E8E8E8")?.cgColor
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
